<template>
	<view class="content">
		<view class="data-waik" :style="[backStyle]">
			<scroll-view scroll-y="true" class="scroll" @scrolltolower="scrolltolower">
				<div class="waterfall">
				    <div class="item" @click="setUrl(item.id,item.type)" v-for="(item,index) in dataList" :key="index">
				        <div class="item-content">
							<image src="../../../static/img/spbf.png" v-if="item.type == 2" style="width: 50rpx;height: 50rpx;position: absolute;right: 15rpx;top: 15rpx;z-index: 11;" mode=""></image>
							<view class="item-content-img">
								<image :src="item.cover" mode="widthFix"></image>
							</view>
							<view class="item-title">
								{{item.title?item.title:'暂无'}}
							</view>
							<view class="item-user">
								<view class="item-user-left">
									<image :src="item.userAvatar"></image>
									<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{item.userName}}</span>
								</view>
								<view class="item-user-right">
									<span>{{item.views}}</span>
									<u-icon name="eye" color="#666666" style="margin-right: 10rpx;" size="28"></u-icon>
								</view>
							</view>
				        </div>
				    </div>
				</div>
				<view v-if="onShow" style="width: 100%;height: 100rpx;display: flex;align-items: center;justify-content: center;color: #bcbcbc;">
					到底了，没有更多了~
				</view>
				<view class="adopt-empty" v-if="dataList.length === 0 && loading === false">
					<u-image width="400rpx" height="280rpx" src="@/static/user/none1.png" :lazy-load="true"></u-image>
					<view class="empty-text">暂无数据~</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			dataList: [],
			page:1,
			size: 10,
			onShow: false,
			total: 0,
			loading: true
		}
	},
	onPageScroll: function(e) {
		this.scrollTop = e.scrollTop;
	},
	onPullDownRefresh() {
		this.onShow = false
		this.page = 1
		this.getData()
		setTimeout(function () {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onLoad() {

	},
	methods: {
		// 加载中
		showLoading () {
			this.loading = true
			uni.showLoading({
			    title: '正在加载中',
				mask: true
			});
		},
		// 加载成功
		hideLoading () {
			uni.showToast({
			    title: '加载成功',
				icon: 'success',
				mask: true,
				complete: () =>{
					uni.hideLoading();
					this.loading = false
				}
			});
		},
		getData(){
			this.showLoading()
			let self = this;
			self.$request(self.commonApi.diaryCollect+self.page+'/'+self.size,'GET').then(res=>{
				self.total = res.data.data.meta.total
				self.dataList = res.data.data.result
				this.hideLoading()
			})
		},
		setUrl(id,type){
			uni.navigateTo({
				url: '../../diary/Detail/diaryDetail?id='+id
			})
		},
		scrolltolower(){
			let self = this;
			if(self.dataList.length < self.total){
				self.page += 1
				self.$request(self.commonApi.diaryCollect+self.page+'/'+self.size,'GET').then(res=>{
					let data = res.data.data.result
					data.forEach(item=>{
						self.dataList.push(item)
					})
				})
			}else{
				self.onShow = true
			}
		}
	},
	onShow() {
		this.getData()
	},
	mounted() {
		
	},
	computed: {
		backStyle () {
			let style = {}
			let background = ''
			if (this.dataList.length === 0) {
				background = '#fff'
			} else {
				background = '#f2f2f2'
			}
			style.background = background
			return style
		}
	}
}
</script>

<style lang="scss" scoped>
	.adopt-empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 200rpx;
		.empty-text {
			font-size: 32rpx;
			font-weight: 500;
			color: #333333;
			line-height: 44rpx;
			letter-spacing: 2rpx;
			padding-top: 60rpx;
		}
	}
	.item-user-left{
		width: 230rpx;
		display: flex;
		align-items: center;
		flex-direction: row;
		image{
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			
		}
		span{
			margin-left: 10rpx;
		}
	}
	.item-user-right{
		width: 100rpx;
		display: flex;
		align-items: center;
		flex-direction: row-reverse;
	}
	.item-user{
		width: 100%;
		height: 70rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		font-size: 26rpx;
		color: #666666;
		padding: 0 15rpx;
	}
	.waterfall{
		width: 100%;
	    column-count: 2;
	    column-gap: 0;
	}  
	.item{
	    box-sizing: border-box;
	    break-inside: avoid;
	    padding:8rpx 15rpx 20rpx 15rpx;
	}
	.item-title{
		width: 100%;
		max-height: 96rpx;
		padding: 15rpx 15rpx 20rpx 15rpx;
		font-size: 28rpx;
		font-weight: bold;
		// background: white;
		color: #313131;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
	.item-content{
		width: 330rpx;
	    display: flex;
	    flex-direction: column;
	    justify-content: center;
	    align-items: center;
	    height: auto;
	    box-sizing: border-box;
	    background: white;
		overflow: hidden;
		border-radius: 15rpx;
		position: relative;
		.item-content-img{
			width: 100%;
			image{
				width: 100%;
				min-height: 100%;
				zoom: 0.5;
				border-radius: 15rpx 15rpx 0 0;
				position: relative;
				z-index: 10;
			}
		}
	}
	
	.data-waik{
		width: 100%;
		height: calc(100vh - 50rpx);
		padding-top: 30rpx;
		// position: absolute;
		// top: 200rpx;
		// left: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.scroll{
		width: 720rpx;
		height: calc(100vh - 50rpx);
		display: flex;
		align-items: center;
	}
	
	.content {
		width: 100%;
		height: 100vh;
		background: #f2f2f2;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

</style>
